package com.itheima.mapper;

import com.itheima.pojo.NewShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface NewShoppingCartMapper {
    // 根据买家id选择
    @Select("select * from new_shopping_cart where buyer_id = #{buyerId}")
    @ResultMap("newShoppingCartResultMap")
    List<NewShoppingCart> selectByBuyerId(Integer buyerId);

    @Select("select * from new_shopping_cart where buyer_id = #{buyerId} and item_id = #{itemId}")
    @ResultMap("newShoppingCartResultMap")
    List<NewShoppingCart> selectByBuyerIdAndItemId(@Param("itemId") Integer itemId, @Param("buyerId") Integer buyerId);

    @Update("update new_shopping_cart set item_quantity = #{itemQuantity} where buyer_id = #{buyerId} and item_id = #{itemId}")
    @ResultMap("newShoppingCartResultMap")
    void updateItemQuantity(@Param("itemId") Integer itemId, @Param("buyerId") Integer buyerId, @Param("itemQuantity") Integer itemQuantity);

    @Insert("insert into new_shopping_cart values(null,#{buyerId},#{itemId},#{itemQuantity})")
    @ResultMap("newShoppingCartResultMap")
    void add(@Param("itemId") Integer itemId, @Param("buyerId") Integer buyerId, @Param("itemQuantity") Integer itemQuantity);

    @Delete("delete from new_shopping_cart where buyer_id = #{buyerId} and item_id = #{itemId}")
    @ResultMap("newShoppingCartResultMap")
    void delete(@Param("itemId") Integer itemId, @Param("buyerId") Integer buyerId);
}
